//
//  SettingCell.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/8.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class SettingCell: UITableViewCell {

    // MARK: - life cycle
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initBaseLayouot()
        layoutPageSubviews()
        self.selectionStyle = .none
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - private method
    func initBaseLayouot() {
        self.addSubview(contentLabel)
        self.addSubview(arrowImageView)
        self.addSubview(versionLabel)
    }
    
    func layoutPageSubviews() {
        contentLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(14)
            make.centerY.equalTo(self)
            make.width.equalTo(58)
            make.height.equalTo(14)
        }
        
        arrowImageView.snp.makeConstraints { (make) in
            make.right.equalTo(-16)
            make.centerY.equalTo(self)
            make.width.equalTo(6)
            make.height.equalTo(12)
        }
        
        versionLabel.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-14)
            make.centerY.equalTo(self)
            make.width.equalTo(200)
            make.height.equalTo(14)
        }
    }
    
    func configUI(content: String) {
        contentLabel.text = content
    }
    
    // MARK: - setters and getters
    var _isVersion: Bool?
    var isVersion: Bool? {
        set {
            if newValue! {
                versionLabel.isHidden = false
                arrowImageView.isHidden = true
                versionLabel.text = "v2.7"
            } else {
                versionLabel.isHidden = true
                arrowImageView.isHidden = false
            }
        } get {
            return _isVersion
        }
        
    }
    
    var _isPhone: Bool?
    var isPhone: Bool? {
        set {
            if newValue! {
                versionLabel.isHidden = false
                arrowImageView.isHidden = true
                versionLabel.text = "400 890 6878"
            } else {
                versionLabel.isHidden = true
                arrowImageView.isHidden = false
            }
            
        } get {
            return _isPhone
        }
    }
    
    var _contentLabel: UILabel!
    var contentLabel: UILabel {
        if _contentLabel == nil {
            _contentLabel = UILabel()
            _contentLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _contentLabel.textColor = UIColor(hexString: "#252525")
        }
        return _contentLabel
    }
    
    var _arrowImageView: UIImageView!
    var arrowImageView: UIImageView {
        if _arrowImageView == nil {
            _arrowImageView = UIImageView()
            _arrowImageView.image = UIImage(named: "icon_arrow_r")
        }
        return _arrowImageView
    }
    
    var _versionLabel: UILabel!
    var versionLabel: UILabel {
        if _versionLabel == nil {
            _versionLabel = UILabel()
            _versionLabel.font = UIFont.systemFont(ofSize: 13)
            _versionLabel.textColor = UIColor(hexString: "#999999")
            _versionLabel.textAlignment = .right
        }
        return _versionLabel
    }
    
}
